package com.hulu.yec.teach.examplan.common;

import java.util.List;

public class PageModel<T> {

	// 每次查询到的分页数据;
	private List<T> list;
	// 从哪一页开始，默认是1；
	private int pageNo;
	// 每页显示多少条数据，默认10条;
	private int pageSize;
	// 总共有多少条数据;
	private int allRecords;

	public PageModel() {
		super();
	}

	public PageModel(List<T> list, int pageNo, List<Integer> lists,
			int pageSize, int allRecords) {
		super();
		this.pageNo = pageNo;
		this.list = list;
		this.pageSize = pageSize;
		this.allRecords = allRecords;
	}

	public PageModel(List<T> list, int pageNo, int pageSize, int allRecords) {
		super();
		this.list = list;
		this.pageNo = pageNo;
		this.pageSize = pageSize;
		this.allRecords = allRecords;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getAllRecords() {
		return allRecords;
	}

	public void setAllRecords(int allRecords) {
		this.allRecords = allRecords;
	}

	/**
	 * 总共有多少页
	 */
	public int getTotalPage() {
		// (pageNo + PageSize-1)/pageSize
		return (int) Math.ceil((double) allRecords / pageSize);
	}

	/**
	 * 首页
	 */
	public int getFirst() {
		if (getTotalPage() == 0) {
			return getTotalPage();
		} else {
			return 1;
		}
	}

	/**
	 * 上一页
	 */
	public int getPre() {
		if (pageNo == 1 && getTotalPage() != 0) {
			return 1;
		} else {
			if (getTotalPage() == 0) {
				return getTotalPage();
			}
			return pageNo - 1;
		}
	}

	/**
	 * 下一页
	 */
	public int getNext() {
		if (pageNo == getTotalPage()) {
			return getTotalPage();
		} else {
			if (getTotalPage() == 0) {
				return getTotalPage();
			}
			return pageNo + 1;
		}
	}

	/**
	 * 尾页
	 */
	public int getLast() {
		return getTotalPage();
	}

}
